package com.easy.west.westclient.api.workplan.baen;

import android.annotation.SuppressLint;

import com.alamkanak.weekview.WeekViewEvent;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Event {

    /**
     * id : 5
     * content : 全天
     * starttime : 已设置置顶为目标全天任务
     * endtime : 已设置置顶为目标全天任务
     * top : true
     * date : 2018-07-04
     */

    private long id;
    private String content;
    private String starttime;
    private String endtime;
    private boolean top;
    private String date;
    private int dayofmoth;
    public long getId() {
        return id;
    }

    public int getDayofmoth() {

            dayofmoth = Integer.parseInt(getDate().split("-")[2]);
        return dayofmoth;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getStarttime() {
        return starttime;
    }

    public void setStarttime(String starttime) {
        this.starttime = starttime;
    }

    public String getEndtime() {
        return endtime;
    }

    public void setEndtime(String endtime) {
        this.endtime = endtime;
    }

    public boolean isTop() {
        return top;
    }

    public void setTop(boolean top) {
        this.top = top;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    @SuppressLint("SimpleDateFormat")
    public WeekViewEvent toWeekViewEvent(){
        String start_time = getDate()+" "+getStarttime();
        String end_time = getDate()+" "+getEndtime();
        // Parse time.
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date start = new Date();
        Date end = new Date();
        //再这里转换
        try {
            start = sdf.parse(start_time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            end = sdf.parse(end_time);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        // Initialize start and end time.
        Calendar now = Calendar.getInstance();
        now.setTime(start);
        Calendar startTime = (Calendar) now.clone();
        startTime.setTimeInMillis(start.getTime());
        startTime.set(Calendar.YEAR, now.get(Calendar.YEAR));
        startTime.set(Calendar.MONTH, now.get(Calendar.MONTH));
        startTime.set(Calendar.DAY_OF_MONTH, getDayofmoth());
        Calendar endTime = (Calendar) startTime.clone();
        endTime.setTimeInMillis(end.getTime());
        endTime.set(Calendar.YEAR, startTime.get(Calendar.YEAR));
        endTime.set(Calendar.MONTH, startTime.get(Calendar.MONTH));
        endTime.set(Calendar.DAY_OF_MONTH, startTime.get(Calendar.DAY_OF_MONTH));

        // Create an week view event.
        WeekViewEvent weekViewEvent = new WeekViewEvent();
        weekViewEvent.setName(getContent());
        weekViewEvent.setStartTime(startTime);
        //这啥？
        weekViewEvent.setLocation("高博汇科");
        weekViewEvent.setEndTime(endTime);
        weekViewEvent.setAllDay(top);
        weekViewEvent.setId(id);
        weekViewEvent.setColor(0);
        //weekViewEvent.setColor(Color.parseColor(getColor()));

        return weekViewEvent;
    }
    /***
     * 根据stringdate获取时间
     * @param date
     * @return
     */
    private int getMonthByData(String date)
    {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
        Date time = null;
        try {
            time = dateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.setTime(time);
        return calendar.get(java.util.Calendar.MONTH)+1;
    }
    /***
     * 根据stringdate获取年份
     * @param date
     * @return
     */
    private int getYearByData(String date) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
        Date time = null;
        try {
            time = dateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        calendar.setTime(time);
        return calendar.get(java.util.Calendar.YEAR);
    }

}